﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MinerManager
{
	public partial class Utility
	{
		public class MinerHttpRequest
		{
			private static readonly string Url = "http://superminer.ltcc.ren/home/";

			#region McsUtility.Models.ResultModel SendSMSCode(string phone) 发送验证码。

			/// <summary>
			/// 发送验证码。
			/// </summary>
			/// <param name="phone">电话号</param>
			/// <returns></returns>
			public static McsUtility.Models.ResultModel SendSMSCode(string phone)
			{
				McsUtility.Models.ResultModel result = new McsUtility.Models.ResultModel
				{
					success = false,
					message = "未知错误。"
				};

				string url = Url + "GetRegSMSCode";
				string queryString = "LoginName=" + phone;

				try
				{
					string html = Get(url + "?" + queryString, Encoding.UTF8);
					result = TomNet.Utility.Data.JsonHelper.FromJson<McsUtility.Models.ResultModel>(html);
				}
				catch
				{
					result.message = "数据请求或解析错误。";
				}

				return result;
			}

			#endregion

			#region McsUtility.Models.ResultModel Register(string userName, ...) 注册。

			/// <summary>
			/// 注册。
			/// </summary>
			/// <param name="userName">登录名（手机号）</param>
			/// <param name="passWord">登录密码</param>
			/// <param name="smsCode">验证码</param>
			/// <param name="staffId">客户经理Id</param>
			/// <param name="realName">姓名</param>
			/// <param name="qq">QQ</param>
			/// <param name="wechat">微信</param>
			/// <returns></returns>
			public static McsUtility.Models.ResultModel Register(string userName, string passWord, string smsCode, string staffId, string realName = "", string qq = "", string wechat = "")
			{
				McsUtility.Models.ResultModel result = new McsUtility.Models.ResultModel
				{
					success = false,
					message = "未知错误"
				};

				string url = Url + "Reg";
				string queryString = "LoginName=" + userName
					+ "&LoginPass=" + passWord
					+ "&SMSCode=" + smsCode
					+ "&Name=" + realName
					+ "&PassQuestion1=" + qq
					+ "&PassQuestion2=" + wechat
					+ "&PassQuestion3=" + staffId
					+ "&sec=1";

				try
				{
					string html = Get(url + "?" + queryString, Encoding.UTF8);
					result = TomNet.Utility.Data.JsonHelper.FromJson<McsUtility.Models.ResultModel>(html);
				}
				catch
				{
					result.message = "数据请求或解析错误。";
				}

				return result;
			}

			#endregion

			//#region McsUtility.Models.LoginResultModel Login(string userName, string passWord) 登录。

			///// <summary>
			///// 登录。
			///// </summary>
			///// <param name="userName">登录名</param>
			///// <param name="passWord">登录密码</param>
			///// <returns></returns>
			//public static McsUtility.Models.LoginResultModel Login(string userName, string passWord)
			//{
			//	McsUtility.Models.LoginResultModel result = null;

			//	string url = Url + "Login";
			//	string queryString = "LoginName=" + userName
			//		+ "&LoginPass=" + passWord;

			//	try
			//	{
			//		string html = Get(url + "?" + queryString, Encoding.UTF8);
			//		McsUtility.Models.ResultModel model = TomNet.Utility.Data.JsonHelper.FromJson<McsUtility.Models.ResultModel>(html);
			//		if (model.success)
			//		{
			//			result = TomNet.Utility.Data.JsonHelper.FromJson<McsUtility.Models.LoginResultModel>(model.data.ToString());
			//		}
			//	}
			//	catch(Exception e) {
			//		string t = "";
			//	}

			//	return result;
			//}

			//#endregion
		}
	}
}
